package com.appjishu.web.biz.service;

import com.appjishu.passport.constant.AuthResponseCode;
import com.appjishu.passport.intercepter.LoginInterceptor;
import com.appjishu.web.biz.cache.BussinessCache;


import com.appjishu.web.biz.dao.SpecialityMapper;
import com.appjishu.web.biz.dao.UserMapper;
import com.appjishu.web.model.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

@Service
public class RankingService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private SpecialityMapper specialityMapper;

    @Autowired
    private BussinessCache bussinessCache;


    public Map<String,Object> rankingListByCondition() {
        Long userId = LoginInterceptor.getUserId();
        User users = userMapper.selectAll(userId);
        RankingListByAllCondition rankingListByAllCondition = new RankingListByAllCondition();
        rankingListByAllCondition.setRankingByAll(userMapper.rankingByAll());
        rankingListByAllCondition.setRankingByCollegeId(userMapper.rankingByCollegeId(users.getCollegeId()));
        rankingListByAllCondition.setRankingBySpecialityId(userMapper.rankingBySpecialityId(users.getSpecialityId()));
        rankingListByAllCondition.setRankingByClassId(userMapper.rankingByClassId(users.getClassId()));
        Map<String, Object> map =new HashMap<>();
        StLevel lvName = bussinessCache.getLvName(BigDecimal.valueOf(users.getScore()));
        map.put(AuthResponseCode.LEVEL,lvName.getName());
        map.put(AuthResponseCode.CLASSNAME,specialityMapper.selectSpeciality(userId));
        map.put(AuthResponseCode.ALL,rankingListByAllCondition.getRankByAll(userId));
        map.put(AuthResponseCode.COLLEGE,rankingListByAllCondition.getRankingByCollegeId(userId));
        map.put(AuthResponseCode.SPECIALITY,rankingListByAllCondition.getRankingBySpecialityId(userId));
        map.put(AuthResponseCode.CLASS,rankingListByAllCondition.getRankingByClassId(userId));
        return map;
    }
}

